package com.gg.registration.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gg.common.result.CommonResult;
import com.gg.common.result.ResultCodeEnum;
import com.gg.registration.model.user.UserInfo;
import com.gg.registration.user.service.UserInfoService;
import com.gg.registration.vo.acl.UserQueryVo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gg.registration.vo.user.UserInfoQueryVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 后台管理系统操作用户的controller
 *
 * Author：  chenjunjia
 * Date：    2022/4/22 10:55
 * WeChat：  China_JoJo_
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    UserInfoService userInfoService;

    /**
     * 分页查询用户列表
     * @param page 当前页
     * @param limit 每页显示记录数
     * @return 统一返回结果集
     */
    @GetMapping("/{page}/{limit}")
    public CommonResult userList(@PathVariable("page") Long page,
                                 @PathVariable("limit") Long limit,
                                 UserInfoQueryVo userQueryVo) {
        IPage<UserInfo> pageModel = userInfoService.selectPage(page,limit,userQueryVo);
        return null!=pageModel?new CommonResult(ResultCodeEnum.SUCCESS,pageModel):new CommonResult(ResultCodeEnum.FAIL);
    }

    /**
     * 锁定用户状态
     * @param userId userinfo表主键id
     * @param status 状态参数
     * @return 统一返回结果集
     */
    @GetMapping("lock/{userId}/{status}")
    public CommonResult lock(
            @PathVariable("userId") Long userId,
            @PathVariable("status") Integer status){
        userInfoService.lock(userId, status);
        return new CommonResult(ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据userinfo表的主键id查询用户信息以及就诊人信息
     * @param id 主键id
     * @return 统一返回结果集
     */
    @GetMapping("show/{id}")
    public CommonResult show(@PathVariable("id") String id) {
        Map<String,Object> map = userInfoService.show(Long.valueOf(id));
        return new CommonResult(ResultCodeEnum.SUCCESS,map);
    }

    //认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public CommonResult approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return new CommonResult(ResultCodeEnum.SUCCESS);
    }
}
